let postId = getQuery("postId");
console.log(postId)
window.onload=function () {
    findById()
}
function findById() {
    axios.get("/post/findById",{
        params:{
            id:postId
        }
    }).then(resp=>{
        let info = resp.data;
        $("title").innerHTML = info.theme
        $("name").innerHTML=info.userBean.username
        $("img").src="/img/"+info.userBean.imgPath
        $("img").width = "50";
        $("img").height = "50";
        $("createDate").innerHTML = info.userBean.createDate

        $("post-title").innerHTML = info.theme
        $("post-time").innerHTML = info.createDate
        console.log(resp.data)
        let str=""
        info.replyList.forEach(n=>{
            str += `<span>${n.title}:${n.content}</span><br>`
        })

        $("replyList").innerHTML = str;
    })
}


function addReply() {
    console.log("++++++++++6++++")
    axios.get("/reply/add",{
        params: {
            postId:postId,
            title:$("replyTitle").value,
            content:$("replyContent").value,
        }
    }).then(resp => {
        let info = resp.data;
        console.log(info)
        console.log("++++++++++6++++")
        if (info == "ok"){
            findById()
            $("replyTitle").value="";
            $("replyContent").value="";
        }else if (info=="no"){
                location.href="/login.html";
        }
    })
}

